package com.fileshare.web.controller.index.view;

import com.fileshare.web.controller.index.BaseController;
import com.fileshare.web.dto.Vo.ArticleVo;
import com.fileshare.web.dto.info.WebInfo;
import com.fileshare.web.properties.WebProperties;
import com.fileshare.web.service.ArticleService;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 分类导航
 */
@Controller
@RequestMapping("/classify")
public class ClassifyController extends BaseController {
    @Resource
    private WebProperties webProperties;
    @Resource
    private ArticleService articleService;

    @GetMapping("")
    public String allClassify(HttpServletRequest request) {
        WebInfo info = new WebInfo();
        info.setTitle("FileShare 主页");
        request.setAttribute("webInfo", info);
        return view("classify/all");
    }

    @GetMapping("/{categoryName}")
    public String oneClassify(HttpServletRequest request, @PathVariable String categoryName) {
        WebInfo info = new WebInfo();
        info.setTitle("FileShare 主页");
        PageInfo<ArticleVo> articles = articleService.getArticlesByCategoryName(categoryName);
        info.setTitle("资源分类 : " + categoryName);
        request.setAttribute("webInfo", info);
        request.setAttribute("articles", articles);
        request.setAttribute("categoryName", categoryName);
        return view("classify/category");
    }
}
